package com.huqing.icu.controller;

import com.huqing.icu.base.BaseController;
import com.huqing.icu.base.IdReq;
import com.huqing.icu.inout.in.CommentAddReq;
import com.huqing.icu.inout.in.CommentListQueryReq;
import com.huqing.icu.inout.in.CommentReplyReq;
import com.huqing.icu.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 评论接口
 *
 * @author huqing
 * @date 2024-11-23 13:14
 */

@RestController
@RequestMapping("/api/comment")
@Tag(name = "评论接口")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;


    @Operation(summary = "新增一级评论")
    @PostMapping("/addComment")
    public String addComment(@Valid @RequestBody CommentAddReq addReq) {
        return jsonSuccessForNull(commentService.addComment(addReq));
    }

    @Operation(summary = "回复评论")
    @PostMapping("/replyComment")
    public String replyComment(@Valid @RequestBody CommentReplyReq replyReq) {
        return jsonSuccessForNull(commentService.replyComment(replyReq));
    }

    @Operation(summary = "删除评论")
    @PostMapping("/deleteComment")
    public String deleteComment(HttpServletRequest request, @RequestBody IdReq idReq) {
        Long userId = checkAndGetUserId(request);
        return jsonSuccessForNull(commentService.deleteComment(idReq.getId(), userId));
    }


    @Operation(summary = "点赞或取消点赞评论")
    @PostMapping("/likeComment")
    public String likeComment(HttpServletRequest request, @RequestBody IdReq idReq) {
        Long userId = checkAndGetUserId(request);
        return jsonSuccessForNull(commentService.likeComment(idReq.getId(), userId));
    }

    @Operation(summary = "查询评论列表")
    @PostMapping("/queryCommentList")
    public String queryCommentList(HttpServletRequest request, @Valid @RequestBody CommentListQueryReq queryReq) {
        Long userId = checkAndGetUserId(request);
        return jsonSuccessForNull(commentService.queryCommentList(queryReq));
    }


}
